package demo.day11_CollectionAddpackage;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/1-08-01-17:24
 * @Description：demo.day11_CollectionAddpackage
 */
public class String_work {
    public static void main(String[] args) {
        String str1 = "hello";
        String str2 = "hello";
        String str3 = new String("hello");
        String str4 = new String("hello");
        String str5 = "hellohello";
        String str6 =str1+str2;
        System.out.println("str1==str2?"+(str1==str2));     //true     字符串常量池
        System.out.println("str2==str3?"+(str2==str3));     //false    比较的为地址
        System.out.println("str3==str4?"+(str3==str4));     //false    比较的为地址
        System.out.println("str2.equals(str3)?"+(str2.equals(str3)));  //true     重写了equals方法比较的为值
        System.out.println("str3.equals(str4)?"+(str3.equals(str4)));    //true
        System.out.println(str5.equals(str6));    //true
        System.out.println(str5==str6);          //false       地址不同

        String s1="helloworld";
        String s2="hello";
        String s3="world";
        String s4="hello"+"world";
        String s5=s2+s3;
        String s6=new String("helloword");
        String s7="hello"+new String("world");
        System.out.println(s1==s4);        //false 拼接的字符串是通过new创建的，s1在字符串常量池中
        System. out. println(s1==s5);      //false  s2、s3、再拼接，依旧是动态创建，
        System. out. println(s1==s6);      //false  通过new创建的字符串，地址都不会相等
        System. out. println(s1==s7);     //false
    }
}
